﻿using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace ETS_FinancialData_sync_toolsForServer
{
    public class Login : CommandBase<TelnetSession, StringRequestInfo>
    {
        public delegate void PacUpdateDelegate(string pac);

        public static event PacUpdateDelegate OnPacUpdateEvent;

        protected virtual void OnNumChanged()
        {
            if (OnPacUpdateEvent != null)
            {
                OnPacUpdateEvent(sb.ToString());
            }
            else
            {
                Console.WriteLine("Event fired!");
            }

        }
        public StringBuilder sb = new StringBuilder();
        public int count = 0;
        public override void ExecuteCommand(TelnetSession session, StringRequestInfo requestInfo)
        {
            sb.Remove(0, sb.Length);
            Console.WriteLine("Received Key:" + requestInfo.Key);
            Console.WriteLine("Received Body :" + requestInfo.Body);
            session.Send(string.Format("{0}##{1};", "login", "json from client" + requestInfo.Body.Trim()));
            count++;
            sb.Append(count.ToString());
            OnNumChanged();
            //if (requestInfo.Parameters.Length >0 )
            //{
            //    string param = "";
            //    foreach (var item in requestInfo.Parameters)
            //    {
            //        param += item + ",";
            //    }
            //    param = string.Format("[{0}]", param.Substring(0, param.Length - 1));
            //    Console.WriteLine("Received Parameters :" + param);
            //    //session.Send(string.Format("{0}#{1};", "Login", param));            
            //    session.ID = requestInfo.Parameters[0];
            //    session.Code = requestInfo.Parameters[1];
            //}
            //else
            //    session.Close();
        }



    }


}
